<?php
use Core\Constant;
use Core\Session\FrontSessionHelper;
use Model\Factory\TableGatewayFactory;

$menuTable = TableGatewayFactory::getMenuTable(FrontSessionHelper::getCurrentLang());
$menu = $menuTable->getMenuByCode(Constant::$FRONT_MENU_CODE_TOPMENU);
$allMenuItem = $menu->getAllMenuItem(1);
unset($allMenuItem[0]);

$right = array();
$result = '<div class="col-md-5 col-sm-8 col-xsm-8">
<div style="z-index:2; background-color: #222222" class="navbar-collapse collapse"><ul class="nav navbar-nav">';

foreach ($allMenuItem as $aMenuItem) {
    $item = $aMenuItem->toArray();
    if(count($right)>0){
        while (count($right)>0 && $right[count($right)-1]['rgt']<$item['rgt']) {
            if($right[count($right)-1]['lft'] < $right[count($right)-1]['rgt'] - 1){
                $result = $result.'</ul></li>';
            }
            array_pop($right);
        }
    }

    if($item['lft'] < $item['rgt'] -1){
        $result = $result.'<li class ="dropdown" ><a href="'.$item["url"].'" class="dropdown-toggle" data-toggle="dropdown">'.$item["label"].'<b class="caret"></b></a>';
        $result= $result.'<ul class="dropdown-menu">';
    }else{
        $result = $result.'<li  ><a href="#">'.$item["label"].'</a>';
        $result= $result.'</li>';
    }
    array_push($right,$item);
}
echo $result.'</ul></div></div>';

?>

